<?xml version="1.0" encoding="UTF-8" ?>    							
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >   						
<mapper namespace="${url.daoPackage}.${className}Mapper" >  						
		  <!-- 查询数据字段 -->															
		  <sql id="selectSql">													
		  	   select
		  	   <#list columns as col>  																
			   	 <#if col_index!=0>,</#if>${col.columnName}  ${col.fieldName}	
			   	</#list>	
			   from ${tableName}													
		  </sql>																		  

		  <!-- 主键作为唯一条件查询 -->														
		  <sql id="whereSqlByKey">												
		  	 <where> 																
			 <#list uniqueIndex.colNames as cn>
				and	${cn} = ${r'#'}{${uniqueIndex.fieldNames[cn_index]}}
			 </#list>
		     </where> 																
		  </sql>																  

		  <!-- 多条件组合查询 -->															
		  <sql id="whereSql">														
		  	 <where> 
		  	 <#list columns as col>																
		  	   <if test="${col.fieldName}   != null   and ${col.fieldName} !=''"> and ${col.columnName} = ${r'#'}{${col.fieldName}} </if>      
		     </#list>
		     </where> 																
		  </sql>   																  

		  <!-- 获取列表 -->																
		  <select id="getList" parameterType="${className}" resultType="${className}">	
			   <include refid="selectSql"></include>								
			   <include refid="whereSql"></include>								
		  </select>																  

		  <!-- 获取单条信息 -->															
		  <select id="get" parameterType="${className}" resultType="${className}">		
			   <include refid="selectSql"></include>								
			   <include refid="whereSqlByKey"></include>							
		  </select>																  

		  <!-- 新增 -->																
		  <insert id="add" parameterType="${className}">						
		       insert into ${tableName}(											
		       <trim prefix="" prefixOverrides=",">	
		       <#list columns as col>
		       	  <if test="${col.fieldName} != null">,${col.columnName}</if>  
		       </#list>							
		       </trim>																
		       )values(																
		       <trim prefix="" prefixOverrides=",">	
		       <#list columns as col>
		       	  <if test="${col.fieldName} != null">,${r'#'}{${col.fieldName}}</if>  
		       </#list>			       							
		       </trim>																
		       )																	
		  </insert> 															  

		  <!-- 修改 -->																
		  <update id="update" parameterType="${className}">					
		      update ${tableName}													
		      <set>
		      <#list columns as col>
		      	 ${col.columnName}   =  ${r'#'}{${col.fieldName},jdbcType=${col.jdbcType}},   		      
		      </#list>																	
		      </set>																
		      <include refid="whereSqlByKey"></include>							
		  </update>  															  

		  <!-- 删除 -->																
		  <delete id="delete" parameterType="${className}">					
		      delete from ${tableName} 											
		      <include refid="whereSqlByKey"></include>							
		  </delete>																  

</mapper>    																	

